<template>
	<view class="cldkgbdjr" v-if="showpage">
		<view class="close" @click.stop="showpage=false;">×</view>
		<view class="main">
			<view class="title">
				<input type="text" v-model="ser.key" class="serkey" placeholder="输入名称快速查找项目" @input="changeFunc" />
			</view>
			<scroll-view class="m" :scroll-y="true">
				<view class="item" v-for="item in list" :key="item.id" @click.stop="checkClick(item)">
					{{item.name}}
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import projectapi from '@/api/project';
	export default {
		data() {
			return {
				showpage: false,
				ser: {
					key: '',
					page: 1,
					row: 100
				},
				list: [],
				total: 0,
			}
		},
		computed: {
			totalPage() {
				return Math.ceil(this.total / this.ser.row);
			}
		},
		methods: {
			show() {
				this.showpage = true;
				this.search();
			},
			search() {
				projectapi.noprepareproject(this.ser).then(({ items, total }) => {
					this.list = items;
					this.total = total;
				});
			},
			changeFunc() {
				if (this.cto) {
					clearTimeout(this.cto);
				}
				this.ser.page = 1;
				this.cto = setTimeout(() => {
					this.ser.page = 1;
					this.search();
				}, 500);
			},
			checkClick({ id, name }) {
				this.$emit('ok', { id, name });
				this.showpage = false;
			}
		},
		mounted() {
			const info = uni.getSystemInfoSync();
			const { width, height } = info.safeArea;
		}
	}
</script>

<style lang="scss" scoped>
	.cldkgbdjr {
		position: fixed;
		top: 0;
		left: 0;
		overflow: hidden;
		width: 100vw;
		height: 100vh;
		z-index: 10000;
		background-color: #00000020;
		display: grid;
		place-items: center center;

		&>.main {
			width: 80vw;
			height: 80vh;
			background-color: white;

			&>.title {
				height: 60px;
				line-height: 40px;
				background-color: #047879;
				display: grid;
				place-items: center center;
			}

			&>.m {
				height: calc(80vh - 60px);
				width: 80vw;

				.item {
					width: 90%;
					margin: auto;
					height: 40px;
					line-height: 40px;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					border-bottom: 1px dotted #ccc;

				}
			}
		}

		.close {
			position: absolute;
			right: 10px;
			top: 10px;
			border: 1px solid black;
			width: 15px;
			height: 15px;
			border-radius: 50%;
			text-align: center;
			line-height: 15px;
		}

		.serkey {
			background-color: white;
			text-indent: 10px;

			::placeholder {
				color: #eee;
			}
		}
	}
</style>